//
//  ZRStatusOriginalView.swift
//  XJ8XWB
//
//  Created by 中二 on 2016/10/27.
//  Copyright © 2016年 中二. All rights reserved.
//

import UIKit

class ZRStatusOriginalView: UIView {

    // 定义一个属性 ViewModel 供外界赋值
    var statusViewModel: ZRStatusViewModel?{
        didSet{
            // 当前的控件赋值了
            // 头像
            headImageView.hm_setImage(withUrlString: statusViewModel?.statusModel?.user?.profile_image_url, placeholderImgName: "avatar_default_big")
            // 昵称
            nameLabel.text = statusViewModel?.statusModel?.user?.name
            // 等级
            membershipImageView.image = statusViewModel?.mbrankImage
            // 认证
            avatarImageView.image = statusViewModel?.verifiedImage
            // 微博正文
            contentLabel.text = statusViewModel?.statusModel?.text
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    
    
    private func setupUI(){
        
        backgroundColor = HMRandomColor()
        // 01 - 添加控件
        addSubview(headImageView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(membershipImageView)
        addSubview(avatarImageView)
        addSubview(contentLabel)
        // 02 - 添加约束
        headImageView.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 35, height: 35))
            make.top.left.equalTo(10)
        }
        
        nameLabel.snp_makeConstraints { (make) in
            make.top.equalTo(headImageView)
            make.left.equalTo(headImageView.snp_right).offset(10)
        }
        
        timeLabel.snp_makeConstraints { (make) in
            make.left.equalTo(nameLabel)
            make.bottom.equalTo(headImageView)
        }
        
        sourceLabel.snp_makeConstraints { (make) in
            make.bottom.equalTo(timeLabel)
            make.left.equalTo(timeLabel.snp_right).offset(10)
        }
        
        membershipImageView.snp_makeConstraints { (make) in
            make.centerY.equalTo(nameLabel)
            make.left.equalTo(nameLabel.snp_right).offset(10)
        }
        
        avatarImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(headImageView.snp_right)
            make.centerY.equalTo(headImageView.snp_bottom)
        }
        contentLabel.snp_makeConstraints { (make) in
            make.top.equalTo(headImageView.snp_bottom).offset(10)
            make.left.equalTo(headImageView)
            make.bottom.equalTo(self).offset(-10)
        }
        
    }
    
    // MARK: - 懒加载控件
    // 01 头像
    private lazy var headImageView: UIImageView = UIImageView(imgName: "avatar_default_big")
    // 02 昵称
    private lazy var nameLabel: UILabel = UILabel(textColor: UIColor.blue, fontSize: HMNormalFontSize, text: "老王")
    // 03 时间
    private lazy var timeLabel: UILabel = UILabel(textColor: ZRZhuColor, fontSize: HMSmallFontSize, text: "时间")
    // 04 来源
    private lazy var sourceLabel: UILabel = UILabel(textColor: ZRZhuColor, fontSize: HMSmallFontSize, text: "来自你家隔壁")
    // 05 微博等级
    private lazy var membershipImageView: UIImageView = UIImageView(imgName: "common_icon_membership")
    // 06 认证
    private lazy var avatarImageView: UIImageView = UIImageView(imgName: "avatar_vgirl")
    // 07 微博正文
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.black, fontSize: HMNormalFontSize, text: "", maxWidth: ZRPingMuW - 20)
}
